﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Com.JunCaiSoft.Common.AssistClass
{
    public class StringAssist
    {
        /// <summary>
        /// 获得字符串中开始和结束字符串中间得值(警告：该方法仅限于不包含特殊符号的字符串)
        /// </summary>
        /// <param name="str">字符串</param>
        /// <param name="s">开始</param>
        /// <param name="e">结束</param>
        /// <returns></returns> 
        public static string GetValue(string str, string s, string e)
        {
            Regex rg = new Regex("(?<=(" + s + "))[.\\s\\S]*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline);
            return rg.Match(str).Value;
        }
        /// <summary>
        /// 获得字符串中开始和结束字符串中间得值
        /// </summary>
        /// <param name="str">字符串</param>
        /// <param name="startStr"></param>
        /// <param name="endStr"></param>
        /// <returns></returns> 
        public static List<String> GetValueInBrackets(string str,string startStr,String endStr)
        {
            Regex rg = new Regex(@"\[(.+?)]", RegexOptions.Multiline | RegexOptions.Singleline);
            str = str.Replace(startStr, "[").Replace(endStr, "]");
            var list = rg.Matches(str);
            List<String> resultList = new List<String>();
            foreach(Match item in list)
            {
                var addValue = item.Value.Replace("[", null);
                addValue = addValue.Replace("]", null);
                resultList.Add(addValue);
            }
            return resultList;
        }
    }
}
